package com.aloda.controller.common;

import com.aloda.dto.PhoneCodeDTO;
import com.aloda.result.Result;
import com.aloda.service.VerifyService;
import com.aloda.vo.VerifyVO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;


/**
 * 通用-验证码接口
 * @author aloda
 * @date 2024/12/20
 */
@RestController
@RequestMapping("/common")
public class VerifyController {

    @Resource
    private VerifyService verifyService;

    /**
     * 获取图形验证码
     * @param request
     * @return
     * @throws IOException
     */
    @GetMapping("/verify")
    public Result<VerifyVO> getCode(HttpServletRequest request) throws IOException {
        VerifyVO verifyVO = verifyService.getImgCode(request);
        return Result.success("验证码获取成功",verifyVO);
    }

    /**
     * 获取手机号验证码
     * @return
     */
    @PostMapping("/code")
    public Result getPhoneCode(@RequestBody PhoneCodeDTO phoneCodeDTO) {
        verifyService.getPhoneCode(phoneCodeDTO);
        return Result.success("发送成功");
    }
}
